package com.ruoyi.web.controller.project;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.project.domain.ProFile;
import com.ruoyi.project.service.IProFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 文档Controller
 * 
 * @author ruoyi
 * @date 2024-12-02
 */
@RestController
@RequestMapping("/project/file")
public class ProFileController extends BaseController
{
    @Autowired
    private IProFileService proFileService;

    /**
     * 查询文档列表
     */
    @PreAuthorize("@ss.hasPermi('project:file:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProFile proFile)
    {
        startPage();
        List<ProFile> list = proFileService.selectProFileList(proFile);
        return getDataTable(list);
    }

    /**
     * 导出文档列表
     */
    @PreAuthorize("@ss.hasPermi('project:file:export')")
    @Log(title = "文档", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProFile proFile)
    {
        List<ProFile> list = proFileService.selectProFileList(proFile);
        ExcelUtil<ProFile> util = new ExcelUtil<ProFile>(ProFile.class);
        util.exportExcel(response, list, "文档数据");
    }

    /**
     * 获取文档详细信息
     */
    @PreAuthorize("@ss.hasPermi('project:file:query')")
    @GetMapping(value = "/{fileId}")
    public AjaxResult getInfo(@PathVariable("fileId") Long fileId)
    {
        return success(proFileService.selectProFileByFileId(fileId));
    }

    /**
     * 新增文档
     */
    @PreAuthorize("@ss.hasPermi('project:file:add')")
    @Log(title = "文档", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProFile proFile)
    {
        return toAjax(proFileService.insertProFile(proFile));
    }

    /**
     * 修改文档
     */
    @PreAuthorize("@ss.hasPermi('project:file:edit')")
    @Log(title = "文档", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProFile proFile)
    {
        return toAjax(proFileService.updateProFile(proFile));
    }

    /**
     * 删除文档
     */
    @PreAuthorize("@ss.hasPermi('project:file:remove')")
    @Log(title = "文档", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fileIds}")
    public AjaxResult remove(@PathVariable Long[] fileIds)
    {
        return toAjax(proFileService.deleteProFileByFileIds(fileIds));
    }
}
